<?php

/**
 * @Author: suyuan
 * @Email: 819067126@qq.com
 * @Date: 2020/11/13 11:41
 */

namespace app\api\model;

use think\Db;
use think\Model;
use think\model\relation\HasMany;

class Banner extends BaseModel
{
    protected $hidden = ['delete_time','update_time'];
    public function items()
    {
        return $this->hasMany('BannerItem', 'banner_id', 'id');
    }
    public static function getBannerById($id)
    {
        $banner = self::with(['items','items.img'])->find($id);//ORM嵌套关联

        // $result = Db::table('banner_item')->where('banner_id', $id)->select();
        // 原生查询
        // $res = Db::query('SELECT * FROM banner_item WHERE banner_id = ?', [$id]);
        return $banner;
    }
}
